package com.lichuandi.controller;


import com.lichuandi.entity.UserAPI;
import com.lichuandi.entity.UserDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Tag(name = "用户操作接口", description = "用户接口测试")
@RequestMapping("/api")
// @Tag替换API
@Slf4j
public class UserAPIController {

    @Schema(name="获取用户详细信息", description="根据用户的id来获取用户详细信息")
   // @ApiImplicitParam(name = "id", value = "用户ID", required = true,paramType = "query", dataType = "long")
    @Parameter(name = "id", description = "用户id")
    @GetMapping(value="/findById")
    public UserAPI findById(@RequestParam(value = "id")long id){
        return new UserAPI(id,"dalaoyang","123");
    }

   // @ApiOperation(value="保存用户", notes="保存用户")
    @ApiResponse(description = "XXXX", content = @Content(mediaType = "application/json"))
    @PostMapping(value="/saveUser")
    public String saveUser(@RequestBody @Parameter(name="用户对象",description="传入json格式",required=true) UserAPI user){
        return user.toString();
    }

    @ApiResponse(description="修改用户")
    @Parameters({
            @Parameter(name="id",description="主键id",required=true),
            @Parameter(name="username",description="用户名称",required=true),
            @Parameter(name="password",description="用户密码",required=true)
    })
    @GetMapping(value="/updateUser")
    public String updateUser(@RequestParam(value = "id")long id,@RequestParam(value = "username")String username,
                             @RequestParam(value = "password")String password){
        UserAPI user = new UserAPI(id, username, password);
        return user.toString();
    }


    @ApiResponse(description="删除用户")
    @Parameter(name = "id", description = "用户ID", required = true)
    @ApiResponses({
            @ApiResponse(responseCode = "200",description = "成功！"),
            @ApiResponse(responseCode =  "400",description = "未授权！"),
            @ApiResponse(responseCode =  "404",description = "页面未找到！"),
            @ApiResponse(responseCode =  "403",description = "出错了！")
    })
    @DeleteMapping(value="/deleteUserById")
    public String deleteUserById(@RequestParam(value = "id")int id){
        return "success!";
    }

    @Operation(summary = "查询")
    @GetMapping("/query")
    public UserDO query(@Parameter(name = "name", description = "名称") String name) {
        UserDO userDO = new UserDO();
        userDO.setName(name);
        return userDO;
    }

    @Operation(summary = "列表",description = "查询列表")
    @PostMapping("/list")
    public List<UserDO> list() {
        return new ArrayList<UserDO>();
    }

    @Operation(summary ="新增", description = "新增数据")
    @PostMapping("/add")
    public UserDO add(UserDO userDO) {
        return new UserDO();
    }

    @Operation(summary ="修改")
    @PostMapping("/update")
    public UserDO update(UserDO userDO) {
        return new UserDO();
    }

    @Operation(summary ="删除")
    @PostMapping("/delete")
    public Boolean delete(Integer id) {
        return true;
    }
}
